package validator

import (
	validation "github.com/go-ozzo/ozzo-validation/v3"
	"gluenet/pkg/meta"
	interapi "gluenet/pkg/ops/dbi"
	"regexp"
)

func ConfigApplicationValidate(db interapi.GlueDB, config meta.Config) error {
	return validation.ValidateStruct(&config,
		validation.Field(&config.Label, validation.Required, validation.Match(regexp.MustCompile(ResourceConfigApplicationRegexp))),
		validation.Field(&config.Name, validation.Length(1, 255)),
		validation.Field(&config.ConfigValue, validation.NewStringRule(func(s string) bool {
			return true
		}, config.ConfigValue)),
	)
}

func ConfigStrategyValidate(db interapi.GlueDB, config meta.Config) error {
	return validation.ValidateStruct(&config,
		validation.Field(&config.Label, validation.Required, validation.Match(regexp.MustCompile(ResourceConfigStrategyRegexp))),
		validation.Field(&config.Name, validation.Length(1, 255)),
		validation.Field(&config.ConfigValue, validation.NewStringRule(func(s string) bool {
			return true
		}, config.ConfigValue)),
	)
}

func ConfigValidate(db interapi.GlueDB, config meta.Config) error {
	return validation.ValidateStruct(&config,
		validation.Field(&config.Label, validation.Required, validation.Match(regexp.MustCompile(ResourceConfigRegexp))),
		validation.Field(&config.Name, validation.Length(1, 255)),
		validation.Field(&config.ConfigValue, validation.NewStringRule(func(s string) bool {
			return true
		}, config.ConfigValue)),
	)
}
